// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 

package com.yoyo.lib.utilities;

import android.text.TextUtils;
import com.yoyo.lib.AppException;
import java.io.*;

// Referenced classes of package com.stay.lib.utilities:
//            Trace, TextUtil

public final class IOUtilities {

    public IOUtilities() {
    }

    public static void copy(InputStream inputstream, OutputStream outputstream) throws IOException {
        byte abyte0[] = new byte[4096];
        do {
            int i = inputstream.read(abyte0);
            if (i != -1)
                outputstream.write(abyte0, 0, i);
            else
                return;
        } while (true);
    }

    public static byte[] getBytesFromFile(String s)
    {
        byte abyte0[] = null;
        if(!TextUtils.isEmpty(s)) goto _L2; else goto _L1
_L1:
        return abyte0;
_L2:
        FileInputStream fileinputstream;
        ByteArrayOutputStream bytearrayoutputstream;
        try
        {
            fileinputstream = new FileInputStream(new File(s));
            bytearrayoutputstream = new ByteArrayOutputStream(1000);
            byte abyte1[] = new byte[1000];
            do
            {
                int i = fileinputstream.read(abyte1);
                if(i == -1)
                    break;
                bytearrayoutputstream.write(abyte1, 0, i);
            } while(true);
        }
        catch(IOException ioexception)
        {
            Trace.e(ioexception.toString());
            continue; /* Loop/switch isn't completed */
        }
        byte abyte2[];
        fileinputstream.close();
        bytearrayoutputstream.close();
        abyte2 = bytearrayoutputstream.toByteArray();
        abyte0 = abyte2;
        if(true) goto _L1; else goto _L3
_L3:
    }

    public static String readFromFile(String s)
        throws AppException
    {
        ByteArrayOutputStream bytearrayoutputstream;
        FileInputStream fileinputstream;
        if(!TextUtil.isValidate(s))
            throw new AppException(com.stay.lib.AppException.ErrorType.FileException, "FileNotFoundException", (new StringBuilder()).append("the file(").append(s).append(") is not exist").toString(), null);
        bytearrayoutputstream = null;
        fileinputstream = null;
        FileInputStream fileinputstream1 = new FileInputStream(new File(s));
        ByteArrayOutputStream bytearrayoutputstream1 = new ByteArrayOutputStream(1024);
        byte abyte0[] = new byte[1000];
        do
        {
            int i = fileinputstream1.read(abyte0);
            if(i == -1)
                break;
            bytearrayoutputstream1.write(abyte0, 0, i);
        } while(true);
          goto _L1
        FileNotFoundException filenotfoundexception;
        filenotfoundexception;
        fileinputstream = fileinputstream1;
        bytearrayoutputstream = bytearrayoutputstream1;
_L5:
        throw new AppException(com.stay.lib.AppException.ErrorType.FileException, "FileNotFoundException", filenotfoundexception.getMessage(), null);
        Exception exception;
        exception;
_L2:
        IOException ioexception;
        String s1;
        IOException ioexception3;
        IOException ioexception4;
        if(fileinputstream != null)
            try
            {
                fileinputstream.close();
            }
            catch(IOException ioexception2)
            {
                ioexception2.printStackTrace();
            }
        if(bytearrayoutputstream != null)
            try
            {
                bytearrayoutputstream.close();
            }
            catch(IOException ioexception1)
            {
                ioexception1.printStackTrace();
            }
        throw exception;
_L1:
        bytearrayoutputstream1.flush();
        s1 = new String(bytearrayoutputstream1.toByteArray());
        if(fileinputstream1 != null)
            try
            {
                fileinputstream1.close();
            }
            // Misplaced declaration of an exception variable
            catch(IOException ioexception4)
            {
                ioexception4.printStackTrace();
            }
        if(bytearrayoutputstream1 != null)
            try
            {
                bytearrayoutputstream1.close();
            }
            // Misplaced declaration of an exception variable
            catch(IOException ioexception3)
            {
                ioexception3.printStackTrace();
            }
        return s1;
        ioexception;
_L3:
        throw new AppException(com.stay.lib.AppException.ErrorType.FileException, "IOException", ioexception.getMessage(), null);
        exception;
        fileinputstream = fileinputstream1;
          goto _L2
        exception;
        fileinputstream = fileinputstream1;
        bytearrayoutputstream = bytearrayoutputstream1;
          goto _L2
        ioexception;
        fileinputstream = fileinputstream1;
          goto _L3
        ioexception;
        fileinputstream = fileinputstream1;
        bytearrayoutputstream = bytearrayoutputstream1;
          goto _L3
        filenotfoundexception;
        continue; /* Loop/switch isn't completed */
        filenotfoundexception;
        fileinputstream = fileinputstream1;
        if(true) goto _L5; else goto _L4
_L4:
    }

    public static String readStreamToMemory(InputStream inputstream)
        throws AppException
    {
        String s = null;
        if(inputstream != null) goto _L2; else goto _L1
_L1:
        return s;
_L2:
        ByteArrayOutputStream bytearrayoutputstream = null;
        byte abyte0[];
        ByteArrayOutputStream bytearrayoutputstream1;
        abyte0 = new byte[1024];
        bytearrayoutputstream1 = new ByteArrayOutputStream();
        do
        {
            int i = inputstream.read(abyte0);
            if(i == -1)
                break;
            bytearrayoutputstream1.write(abyte0, 0, i);
        } while(true);
          goto _L3
        IOException ioexception;
        ioexception;
        bytearrayoutputstream = bytearrayoutputstream1;
_L7:
        throw new AppException(com.stay.lib.AppException.ErrorType.FileException, "IOException", ioexception.getMessage(), null);
        Exception exception;
        exception;
_L6:
        if(bytearrayoutputstream == null)
            break MISSING_BLOCK_LABEL_86;
        bytearrayoutputstream.close();
        if(inputstream != null)
            inputstream.close();
        if(bytearrayoutputstream != null)
            bytearrayoutputstream.close();
_L5:
        throw exception;
_L3:
        byte abyte1[] = bytearrayoutputstream1.toByteArray();
        if(bytearrayoutputstream1 == null)
            break MISSING_BLOCK_LABEL_122;
        bytearrayoutputstream1.close();
        if(inputstream != null)
            inputstream.close();
        if(bytearrayoutputstream1 != null)
            bytearrayoutputstream1.close();
_L4:
        s = new String(abyte1);
          goto _L1
        IOException ioexception2;
        ioexception2;
        ioexception2.printStackTrace();
          goto _L4
        IOException ioexception1;
        ioexception1;
        ioexception1.printStackTrace();
          goto _L5
        exception;
        bytearrayoutputstream = bytearrayoutputstream1;
          goto _L6
        ioexception;
          goto _L7
    }

    public static final int IO_BUFFER_SIZE = 4096;
}
